package com.cloudfast.config;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import lombok.Getter;
import lombok.Setter;

/**
 * 文件配置类 自动加载 sftp.client 配置
 *
 * @author liuyw
 */
@Setter
@Getter
@Component
@ConfigurationProperties(prefix = "spring.datasource")
public class EmailDataSource {
    private static final Logger logger = LoggerFactory.getLogger(Logger.class);

    private String url;

    private String username;

    private String password;

    private String driverClassName;

    public Connection getConnection() throws ClassNotFoundException, SQLException {
        // 加载MySql的驱动类
        Class<?> clazz = Class.forName(driverClassName);
        logger.info(clazz.getName());
        return DriverManager.getConnection(url + "&useOldAliasMetadataBehavior=true", username, password);
    }

}
